//
//  VisitorLoginView.swift
//  SinaWeibo--swift
//
//  Created by 蒋春萌 on 15/10/6.
//  Copyright © 2015年 蒋春萌. All rights reserved.
//

import UIKit

//设置代理跳转页面，完成注册和登录
protocol VisitorLoginViewDelegate:NSObjectProtocol{
//    注册
    func visitorWillRegister()
//    登录
    func visitorWillLogin()
}

class VisitorLoginView: UIView {
    
//    代理属性
    weak var visitorLoginDelegate: VisitorLoginViewDelegate?
    
    @IBOutlet weak var smallIcon: UIImageView!
    
    @IBOutlet weak var icon: UIImageView!

    @IBOutlet weak var tipLabel: UILabel!
    
//    设置各个UI界面内容的方法
    func setUIInfo( iconName:String, tipText:String ,isHidden:Bool = false){
    
        icon.image = UIImage(named: iconName)
        tipLabel.text = tipText
        smallIcon.hidden = !isHidden
        
        if(isHidden){
        
            startAnimation()
        }
    }
    
    //        给samallIcon设置转场动画
    func startAnimation(){
    
        let animation = CABasicAnimation(keyPath: "transform.rotation")
//        设置动画属性
        animation.duration = 15
        animation.toValue = 2 * M_PI
        animation.repeatCount = MAXFLOAT
        
//        当动画页面处于非活跃状态时默认为移除，所以需要设置为false-》不移除
        animation.removedOnCompletion = false
        
//        添加到samallIcon的layer上
        smallIcon.layer.addAnimation(animation, forKey: nil)
    }

//    执行协议代理方法
    @IBAction func registerAction(sender: AnyObject) {
        visitorLoginDelegate?.visitorWillRegister()
    }

    @IBAction func loginAction(sender: AnyObject) {
        visitorLoginDelegate?.visitorWillLogin()
    }
}
